using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour//角色移动与加速
{
    public float moveSpeed = 0.01f;
    private float h;
    private float v;
    private Vector3 dir;
    private bool isRunning = false;
    // Start is called before the first frame update
    private void Start()
    {
        CheckRunning();
        PlayerMove();
    }

    // Update is called once per frame
    void CheckRunning()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            isRunning = true;
            moveSpeed = 0.03f;
        }
        else if (Input.GetKeyUp(KeyCode.Space))
        {
            isRunning = false;
            moveSpeed = 0.08f;
        }
    }
    void PlayerMove()
    {
        h = Input.GetAxis("Horizontal");
        v = Input.GetAxis("Vertical");
        dir = new Vector3(h, 0, v);
        transform.LookAt(transform.position + dir);
        transform.Translate(dir * moveSpeed, Space.World);
    }
}
